import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

// https://vitejs.dev/config/
export default defineConfig({
    resolve: {
        alias: {
            '@': path.resolve(__dirname, 'src')
        }
    },
    plugins: [
        vue(),
        AutoImport({
            resolvers: [
                ElementPlusResolver()
            ]
        }),
        Components({
            dirs: [],
            resolvers: [
                ElementPlusResolver()
            ]
        })
    ],
    css: {
        preprocessorOptions: {
            less: {
                additionalData: `@import "${path.resolve(__dirname, 'src/assets/css/global.less')}";`
            }
        }
    },
    server: {
        port: 8081,
        host: '0.0.0.0',
        proxy: {
            '/api': {
                target: 'http://localhost:3002',
                changeOrigin: true,
                rewrite: (path: string) => path.replace(/^\/api/, '/api')
            }
        }
    }
})
